package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.JSONUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 日报
 */
@Setter
@Getter
public class New extends BaseDomain{
    public static final Integer Type_FENG = 1; //风景
    public static final Integer TYPE_CATE = 2; //美食
    public static final Integer TYPE_CELEBRITY = 3; //名人
    public static final Integer TYPE_MILITARY = 4; //军事

    public static final Integer STATE_TEMP = 0; //草稿
    public static final Integer STATE_RELEASE = 1; //发布


    private String title;  //标题

    private String subTitle; //副标题

    private String coverUrl; //背景

    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date createTime; //创建时间

    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date releaseTime; //发布时间

    private Integer type = Type_FENG;   //类型

    private Integer state = STATE_TEMP;   //状态

    private NewContent newContent; //日报内容

    private UserNew userNew;//关联的用户(暂时使用)


    public String getTypeName() {
        String msg = "风景";
        if (type == TYPE_CATE) {
            msg = "美食";
        } else if (type == TYPE_CELEBRITY) {
            msg = "名人";
        } else if (type == TYPE_MILITARY){
            msg = "军事";
        }
        return msg;
    }

    public String getJson() {
        Map<String, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("title", title);
        map.put("subTitle", subTitle);
        map.put("state", state);
        map.put("coverUrl", coverUrl);
        map.put("type", type);
        return JSONUtil.toJSONString(map);
    }

    public String getStateName() {
        String msg = "草稿";
        if (state == STATE_RELEASE) {
            msg = "发布";
        }
        return msg;
    }
}